package com.ypd.show.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.github.pagehelper.PageInfo;
import com.ypd.show.domain.vo.ArticleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ypd.common.annotation.Log;
import com.ypd.common.core.controller.BaseController;
import com.ypd.common.core.domain.AjaxResult;
import com.ypd.common.enums.BusinessType;
import com.ypd.show.domain.Article;
import com.ypd.show.service.IArticleService;
import com.ypd.common.utils.poi.ExcelUtil;

/**
 * 文章操作Controller
 * 
 * @author ye
 * @date 2025-01-02
 */

@RestController
@RequestMapping("/show/article")
@Api(tags = "文章操作Controller")
public class ArticleController extends BaseController
{
    @Autowired
    private IArticleService articleService;

    /**
     * 查询文章操作列表,需要进行多表查询操作,还要查询点击量表
     * @return
     */
    @ApiOperation("查询文章操作列表")
    @PreAuthorize("@ss.hasPermi('show:article:list')")
    @GetMapping("/list")
    public PageInfo<ArticleVo> list(Article article)
    {
        startPage();
        return articleService.selectArticleList(article);

    }


    /**
     * 获取文章操作详细信息
     */
    @ApiOperation("获取文章操作详细信息")
    @PreAuthorize("@ss.hasPermi('show:article:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(articleService.selectArticleById(id));
    }

    /**
     * 新增文章操作,新增对应的点击量表
     */
    @ApiOperation("新增文章操作")
    @PreAuthorize("@ss.hasPermi('show:article:add')")
    @Log(title = "文章操作", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Article article)
    {
        return toAjax(articleService.insertArticle(article));
    }

    /**
     * 修改文章操作
     */
    @ApiOperation("修改文章操作")
    @PreAuthorize("@ss.hasPermi('show:article:edit')")
    @Log(title = "文章操作", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Article article)
    {
        return toAjax(articleService.updateArticle(article));
    }

    /**
     * 删除文章操作
     */
    @ApiOperation("删除文章操作")
    @PreAuthorize("@ss.hasPermi('show:article:remove')")
    @Log(title = "文章操作", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(articleService.deleteArticleByIds(ids));
    }
}
